<?php
	include('game.php');
	include('player.php');
	include('graph.php');
	include('function.php');
	session_start();
	mysql_connect("localhost", "pigeon", "bois");
	mysql_select_db("pigeon");
	if ($_SESSION['active'] == 1)
	{;
		$game = &$_SESSION['game'];
	}
	else
	{
		$game = new game();	
		$_SESSION['game'] = $game;
		$_SESSION['active'] = 1;
	}
	
	// l'affectation du statu de la page
	$statu = "index";
	if (isset($_GET['statu']) and $_GET['statu']== "stat" ){
		$statu="stat";
	}
	elseif (isset($_GET['player'])){
		$statu="statplayer";
	}
	elseif (isset($_GET['statu']) and $_GET['statu']== "create_user" ){
		$statu="create_user";
	}
	elseif (isset($_POST['statu']) and $_POST['statu']== "create" ){
		if (check_player_name($_POST['pseudo'])==false){
			create_player($_POST['pseudo'],$_POST['password']);
		}
	}
	elseif (isset($_POST['statu']) and $_POST['statu']== "modif_user" ){
		if (check_password($_POST['pseudo_modif'],$_POST['password_modif'])){
			$statu="modif_user";
		}
		else{
			$error="Password or pseudo invalid";
		}
	}
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html>
<head>
	<title> this is the pigeon test page </title>
	<link rel="stylesheet" type="text/css" href="pige.css" />
	<script type="text/javascript" src="function.js" ></script>
</head>
<body>
<div>
	<?php
		if (isset($debug) and $debug != ""){
		echo "Debug :".$debug;
		}
		if (isset($error) and $error != ""){
		echo "error :".$error;
		}
		
		if ($statu == "index"){
		?>
		<div id = action>
			<form method="get" action="manage_player.php" />
				<input type="hidden" name="statu" value="stat" />
				<input type="submit" value="stat joueur" />
			</form>
			<form method="get" action="manage_player.php">
				<input type="hidden" name="statu" value="create_user" />
				<input type="submit" value="create user" />
			</form>
			<form method="post" action="manage_player.php">
				Modifier un USER
				<input type="text" name="pseudo_modif" />
				<input type="password" name="password_modif" />
				<input type="hidden" name="statu" value="modif_user" />
				<input type="submit" value="modif user" />
			</form>
		</div>
		<?php
		}
		elseif ($statu == "stat"){
			echo "<table>";
				echo "<tr>";
					echo "<td>";
						echo "Pseudo";
					echo "</td>";
					echo "<td>";
						echo "Nombre de partie";
					echo "</td>";
					echo "<td>";
						echo "Nombre de coup bu";
					echo "</td>";
					echo "<td>";
						echo "Nombre de coup donne";
					echo "</td>";
				echo "</tr>";
			$query=mysql_query("SELECT * FROM players ");
			while ($mysqlplayer = mysql_fetch_array($query)){ 
				echo "<tr>";
					echo "<td>";
						echo "<a href=\"manage_player.php?player=".$mysqlplayer['pseudo']."\">".$mysqlplayer['pseudo']."</a>";
					echo "</td>";
					echo "<td>";
						echo $mysqlplayer['nb_partie'];
					echo "</td>";
					echo "<td>";
						echo $mysqlplayer['nb_coup_bu'];
					echo "</td>";
					echo "<td>";
						echo $mysqlplayer['nb_coup_donne'];
					echo "</td>";
				echo "</tr>";
			}
			echo "</table>";
		}
		elseif ($statu == "statplayer"){
			if (player_exist($_GET['player'])>=1){
			$query=mysql_query("SELECT * FROM players WHERE pseudo = '".$_GET['player']."'");
				while ($mysqlplayer = mysql_fetch_array($query)){
					echo "Pseudo : ".$mysqlplayer['pseudo']."<br />";
					echo "Nombre de partie : ".$mysqlplayer['nb_partie']."<br />";
					echo "Nombre de coup : ".$mysqlplayer['nb_coup_bu']."<br />";
					echo "Nombre de coup donne : ".$mysqlplayer['nb_coup_donne']."<br />";
					echo "Date de dernière partit :".$mysqlplayer['date_derniere_partie'];
				}
			}
			else{
			echo "INVALID USER";
			}
		}
		elseif ($statu == "create_user"){
		?>
		<div id="action">
			<form method="post" action="manage_player.php">
				Pseudo : <input type="text" name="pseudo" /><br />
				Pass : <input type="password" name="password" /><br />
				<!--avatar : <input type="file" name="fichier"><br />-->
				<input type="hidden" name="statu" value="create" /><br />
				<input type="submit" value="create user" />
			</form>
		</div>
		<?php	
		}
		elseif ($statu == "modif_user"){
		?>
		
		<?php
		}
		?>
		
	
</div>
<a href="manage_player.php"> Retour a manage player</a>
</body>
</html>
